<?php

/*
 * This is to update profile of SOB. with image
 */
?>

<?php

include '../../include/config.php';
$target_path = '../../storage/profile_photo/';
$fn = basename($_FILES['uploadedfile']['name']);
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);

if ($fn != '') {
    echo '<br>photo avail<br>';
    if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
//    $fn = basename($_FILES['uploadedfile']['name']);
        $fn = 'profile_' . $_COOKIE['bid'] . substr($_FILES['uploadedfile']['name'], -4);
        rename($target_path,'../../storage/profile_photo/'.$fn);
        mysql_query("update baby_child_profile_detail set  `name`='" . $_POST['name'] . "',sex = '" . $_POST['sex'] . "', photo = '" . $fn . "', date_of_birth='" . $_POST['date_of_birth'] . "', birth_time='" . $_POST['birth_time'] . "', `group` = '" . $_POST['group'] . "', `weight`='" . $_POST['weight'] . "',`height`= '" . $_POST['height'] . "', `birth_type`='" . $_POST['birth_type'] . "', `birth_status` = '" . $_POST['birth_status'] . "' where bid= '" . $_COOKIE['bid'] . "'  ") or die(mysql_error());
        header('Location:../view/Birth?menu=sort_of_birth');
    } else {
        echo "There was an error uploading the file, please try again!";
        header('Location:../view/Birth?menu=sort_of_birth');
    }
} else {
    echo '<br>Without photo<br>' . $_POST['uploadedfile'];
    mysql_query("update baby_child_profile_detail set  `name`='" . $_POST['name'] . "',sex = '" . $_POST['sex'] . "', date_of_birth='" . $_POST['date_of_birth'] . "', birth_time='" . $_POST['birth_time'] . "', `group` = '" . $_POST['group'] . "', `weight`='" . $_POST['weight'] . "',`height`= '" . $_POST['height'] . "', `birth_type`='" . $_POST['birth_type'] . "', `birth_status` = '" . $_POST['birth_status'] . "' where bid= '" . $_COOKIE['bid'] . "'  ") or die(mysql_error());
    header('Location:../view/Birth?menu=sort_of_birth');
}
?>
